import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'login',
      component: LoginView
    },
    {
      path: '/register',
      name: 'register',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/RegisterView.vue')
    },
    {
      path: '/sms_register',
      name: 'sms_register',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/SmsRegisterView.vue')
    },
    {
      path: '/homepage',
      name: 'homepage',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/HomepageView.vue')
    },
    {
      path: '/user_update',
      name: 'user_update',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/UserUpdateView.vue')
    },
    {
      path: '/disease_search',
      name: 'disease_search',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/DiseaseSearchView.vue')
    },
    {
      path: '/disease_detail',
      name: 'disease_detail',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/DiseaseDetailView.vue')
    },
    {
      path: '/doctor_department',
      name: 'doctor_department',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/DoctorDepartmentView.vue')
    },
    {
      path: '/doctor_choose',
      name: 'doctor_choose',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/DoctorChooseView.vue')
    },
    {
      path: '/doctor_detail',
      name: 'doctor_detail',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/DoctorDetailView.vue')
    },
    {
      path: '/doctor_query',
      name: 'doctor_query',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/DoctorQuery.vue')
    },
    {
      path: '/hospital_choose',
      name: 'hospital_choose',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/HospitalChooseView.vue')
    },
    {
      path: '/hospital_detail',
      name: 'hospital_detail',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/HospitalDetailView.vue')
    },
    {
      path: '/history',
      name: 'history',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/HistoryView.vue')
    },
    {
      path: '/admin_login',
      name: 'admin_login',
      component: () => import('../views/AdminLogin.vue'),
      // 任何人都可以阅读文章
      // meta: { requiresAuth: false },
    },
    {
      path: '/dingtalkLogin',
      name: 'dingtalkLogin',
      component: () => import('../views/DingtalkLogin.vue'),
      // 任何人都可以阅读文章
      // meta: { requiresAuth: false },
    },
    {
      path: '/dingtalkCallback',
      name: 'dingtalkCallback',
      component: () => import('../views/DingtalkCallback.vue'),
      // 任何人都可以阅读文章
      // meta: { requiresAuth: false },
    },
    {
      path: '/user_auth',
      name: 'user_auth',
      component: () => import('../views/UserAuth.vue'),
      // 任何人都可以阅读文章
      // meta: { requiresAuth: false },
    },
    {
      path: '/search',
      name: 'search',
      component: () => import('../views/Search.vue'),
      // 任何人都可以阅读文章
      // meta: { requiresAuth: false },
    },
    {
      path: '/order_create',
      name: 'order_create',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/OrderCreateView.vue')
    },
    {
      path: '/order_list',
      name: 'order_list',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/OrderList.vue')
    },
    {
      path: '/upload_file',
      name: 'upload_file',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/UploadFile.vue')
    },
    {
      path: '/websocket',
      name: 'websocket',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Websocket.vue')
    },
    {
      path: '/test',
      name: 'test',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Test.vue')
    },
    {
      path: '/admin',
      component: () => import('../views/Admin.vue'),
      children: [
        {
          path: '/role',
          component: () => import('../components/role.vue'),
          // 只有经过身份验证的用户才能创建帖子
          // meta: { requiresAuth: true },
        },
        {
          path: '/resource',
          component: () => import('../components/Resource.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/trade',
          component: () => import('../components/Resource.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/order',
          component: () => import('../components/Resource.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/coupon',
          component: () => import('../components/Resource.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/create_workflow',
          component: () => import('../components/Create_workflow.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/workflow_role',
          component: () => import('../components/Workflow_role.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/workflow_examine',
          component: () => import('../components/Workflow_examine.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/workflowlist',
          component: () => import('../components/Workflowlist.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/workflow_detail',
          component: () => import('../components/Workflow_detail.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/workflow_approval',
          component: () => import('../components/Workflow_approval.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
        {
          path: '/workflow_approval_detail',
          component: () => import('../components/Workflow_approval_detail.vue'),
          // 任何人都可以阅读文章
          // meta: { requiresAuth: false },
        },
      ]
    },
  ]
})

// 路由守卫，拿到资源的url列表，然后根据url列表判断是否可以访问
// router.beforeEach((to, from, next) => {
//   let white_list = ['/admin_login', '/', '/register', '/sms_register']
//   if(white_list.indexOf(to.path) == -1) {
//     let token = localStorage.getItem('token')
//     if (token) {
//       let url_list = JSON.parse(localStorage.getItem('url_list'))
//       if (url_list.indexOf(to.path) >= 0) {
//         next()
//       }
//       else{
//         alert("无权访问此页面")
//         next({"name": "admin_login"})
//       }
//     }
//     else{
//       next({"name": "admin_login"})
//     }
//   }
//   next()
// })


export default router
